package cn.fancy.sdk.baseview;

import cn.fancy.sdk.common.utils.ResUtil;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class DialogView {
	/**
	 * @param context
	 * @param listener
	 * @return
	 * 等待进度条
	 */
	public static Dialog showWaitingDialog(Context context,
			OnCancelListener listener) {

		LayoutInflater inflater = LayoutInflater.from(context);
		View dialogView = inflater.inflate(ResUtil.getLayoutId(context,"guild_waiting_dialog"), null);
		LinearLayout dialogLayout = (LinearLayout) dialogView
				.findViewById(ResUtil.getId(context,"guild_waiting_dialog_layout"));
		ImageView iv = (ImageView) dialogView
				.findViewById(ResUtil.getId(context,"guild_waiting_img"));
		iv.startAnimation(AnimationUtils.loadAnimation(context,
				ResUtil.getAnimId(context,"guild_waiting_anim")));
		Dialog waitingDialog = new Dialog(context, ResUtil.getStyleId(context,"guild_waiting_dialog"));
		waitingDialog.setContentView(dialogLayout,
				new LinearLayout.LayoutParams(
						LinearLayout.LayoutParams.MATCH_PARENT,
						LinearLayout.LayoutParams.MATCH_PARENT));

		waitingDialog.setCancelable(true);
		waitingDialog.setOnCancelListener(listener);

		waitingDialog.show();
		return waitingDialog;
	}
	
	/**
	 * @param context
	 * @param listener
	 * @return
	 * 等待进度条
	 */
	public static Dialog showWaitingDialog(Context context) {

		LayoutInflater inflater = LayoutInflater.from(context);
		View dialogView = inflater.inflate(ResUtil.getLayoutId(context,"guild_waiting_dialog"), null);
		LinearLayout dialogLayout = (LinearLayout) dialogView
				.findViewById(ResUtil.getId(context,"guild_waiting_dialog_layout"));
		ImageView iv = (ImageView) dialogView
				.findViewById(ResUtil.getId(context,"guild_waiting_img"));
		iv.startAnimation(AnimationUtils.loadAnimation(context,
				ResUtil.getAnimId(context,"guild_waiting_anim")));
		Dialog waitingDialog = new Dialog(context, ResUtil.getStyleId(context,"guild_waiting_dialog"));
		waitingDialog.setContentView(dialogLayout,
				new LinearLayout.LayoutParams(
						LinearLayout.LayoutParams.MATCH_PARENT,
						LinearLayout.LayoutParams.MATCH_PARENT));
		waitingDialog.setCancelable(false);
		waitingDialog.show();
		return waitingDialog;
	}
  /**
 * @param dialog
 * 关闭进度条
 */
public static void cancelDialog(Dialog dialog)
{
		if(dialog!=null && dialog.isShowing())
		{
			dialog.dismiss();
		}
		dialog = null;
  }
}
